import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * datasourceDriver-数据源驱动
 * @date: 2019-08-22
 */
import request from 'utils/request';
import { parseParameters, getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
import { CPAAS_PLATFORM } from 'utils/config';
var prefix = "".concat(CPAAS_PLATFORM, "/v1/").concat(isTenantRoleLevel() ? "".concat(getCurrentOrganizationId(), "/") : "", "datasource-drivers");
/**
 * 分页查询服务驱动列表
 * @param params
 * @returns {Promise<void>}
 */

export function fetchDriversList(_x) {
  return _fetchDriversList.apply(this, arguments);
}
/**
 * 通过 driverId 查询服务驱动明细
 * @param params
 * @returns {Promise<void>}
 */

function _fetchDriversList() {
  _fetchDriversList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request(prefix, {
              method: 'GET',
              query: _objectSpread({}, parseParameters(params))
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchDriversList.apply(this, arguments);
}

export function fetchDriverById(_x2) {
  return _fetchDriverById.apply(this, arguments);
}
/**
 * 创建服务驱动
 * @param params
 * @returns {Promise<void>}
 */

function _fetchDriverById() {
  _fetchDriverById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(prefix, "/").concat(params.driverId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchDriverById.apply(this, arguments);
}

export function createDriver(_x3) {
  return _createDriver.apply(this, arguments);
}
/**
 * 更新服务驱动
 * @param params
 * @returns {Promise<void>}
 */

function _createDriver() {
  _createDriver = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request(prefix, {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _createDriver.apply(this, arguments);
}

export function updateDriver(_x4) {
  return _updateDriver.apply(this, arguments);
}
/**
 * 删除服务驱动
 * @param params
 * @returns {Promise<Object>}
 */

function _updateDriver() {
  _updateDriver = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request(prefix, {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateDriver.apply(this, arguments);
}

export function removeDriver(_x5) {
  return _removeDriver.apply(this, arguments);
}

function _removeDriver() {
  _removeDriver = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request(prefix, {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _removeDriver.apply(this, arguments);
}